home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagg_m.zip / GRAPHICS.SWG / 0039_Another QUICK PutImage.pas < prev    next >
Pascal/Delphi Source File  |  1993-11-02  |  2KB  |  85 lines

  1. (*
  2. SEAN PALMER
  3.  
  4. > there is simple method of masking color 0 so it won't be displayed.
  5. > An assembly language routine based around this:
  6.  
  7. Procedure PutImg(x, y : Integer; Var Img);
  8. Type
  9.   AList = Array[1..$FFFF] of Byte; {1-based Arrays are slower than 0-based}
  10. Var
  11.   APtr    : ^AList; {I found a very fast way to do this: With}
  12.   j, i,
  13.   Width,
  14.   Height,
  15.   Counter : Word;
  16. begin
  17.   Aptr    := @Img;
  18.   Width   := (Aptr^[2] SHL 8) + Aptr^[1] + 1; {these +1's that 1-based Arrays }
  19.   Height  := (Aptr^[4] SHL 8) + Aptr^[3] + 1; { require make For slower code}
  20.   Counter := 5;
  21.   For j := y to (y + height - 1) do
  22.   begin  {try pre-calculating the offset instead}
  23.     For i := x to (x + width - 1) do
  24.     begin
  25.       Case Aptr^[Counter] of {CASE is probably not the way to do this}
  26.         0:; { do nothing }
  27.       else _mcgaScreen[j, i] := Aptr^[Counter]; { plot it }
  28.       end;
  29.       Inc(Counter);
  30.     end;
  31.   end;
  32. end;
  33.  
  34. ok, here's my try:
  35. *)
  36.  
  37. Type
  38.   pWord = ^Word;
  39.  
  40. Procedure putImg(x, y : Integer; Var image);
  41. Var
  42.   anImg : Record
  43.     img : Array [0..$FFF7] of Byte;
  44.   end Absolute image;
  45.  
  46.   aScrn : Record
  47.     scrn : Array [0..$FFF7] of Byte;
  48.   end Absolute $A000 : 0000;
  49.  
  50.   width,
  51.   height,
  52.   counter,
  53.   offs, src : Word;
  54.  
  55. begin
  56.   width  := pWord(@anImg[0])^;
  57.   height := pWord(@anImg[2])^;
  58.   offs   := y * 320 + x;
  59.   src    := 4;   {skip width, height}
  60.   With aScrn, anImg do
  61.   Repeat
  62.     counter := width;
  63.     Repeat
  64.       if img[src] <> 0 then
  65.         scrn[offs] := img[src];
  66.       inc(src);
  67.       inc(offs);
  68.       dec(counter);
  69.     Until counter = 0;
  70.     inc(offs, 320 - width);
  71.     dec(height);
  72.   Until height = 0;
  73. end;
  74.  
  75. {
  76. Those Arrays-pretending-to-be-Records above so they'll work With the With
  77. statement should end up making BP keep the address in Registers, making it
  78. faster. In any Case it won't be slower than yours. I'd appreciate you
  79. timing them and letting me know the results. Actually, let me know if it
  80. even compiles and works... 8)
  81.  
  82. But Really, man, if you're writing Graphics routines you Really have to
  83. go For assembly. Pascal don't cut it. (c doesn't either...)
  84. }
  85.